<?php
declare(strict_types=1);
namespace App\Library\Core;

/*
 * https://open.weibo.com/wiki/Help/error [微博错误码]
 */
class ErrCode
{
    const REQUEST_ILLEGAL   = 10000;
    const PARAM_MISSING     = 10001;
    const REQUEST_TIMEOUT   = 10002;
    const TOKEN_FAIL        = 10003;
    const SERVICE_NOTFOUND  = 10004;
    const RESPONSE_ERR      = 10005;
    const PARAM_REQ_MISSING = 10006;
    const SERVICE_NOT_FOUND = 10007;
    const ERR_SYSTEM        = 10008;
    const ERR_UPLOAD_PATH        = 10009;
    const ERR_HTTP_METHOD        = 10010;
    const SERVER_RESOURCE_UNAVAILABLE = 10011;
    const REMOTE_SERVICE_ERROR = 10012;
    const APPKEY_HIGHER_AUTHORIZATION = 10013;
    const MISSING_SOURCE_PARAMETER = 10014;
    const UNSUPPORTED_MEDIA_TYPE = 10015;
    const SYSTEM_BUSY = 10016;
    const MISSION_TIMEOUTS = 10017;
    const RPC_ERROR = 10018;
    const ILLEGAL_USER = 10019;
    const THREE_PARTY_INTERFACE_LIMITATIONS = 10020;
    const REQUEST_LENGTH_EXCEEDS_LIMIT = 10021;
    const INTERFACE_NOT_EXIST = 10022;
    const IP_REQUEST_EXCEEDS_UPPER_LIMIT = 10023;
    const USER_REQUEST_EXCEEDS_UPPER_LIMIT = 10024;
    const USER_REQUEST_INTERFACE_EXCEEDED_UPPER_LIMIT = 10025;
    const INTERFACE_IS_INVALID = 10026;
    const PARAM_ERROR = 20001;
    const MANDATORY_PARAMETER_MISSING = 20002;
    const PARAM_VALIDATE_ERROR   = 20003;
    const UPLOAD_FASTDFS_ERROR   = 20004;

    static $msg = [
        self::REQUEST_ILLEGAL   => '非法请求',
        self::PARAM_MISSING     => '参数缺失',
        self::REQUEST_TIMEOUT   => '请求超时',
        self::TOKEN_FAIL        => 'token验证失败',
        self::SERVICE_NOTFOUND  => '未发现服务或服务异常',
        self::RESPONSE_ERR      => '返回异常',
        self::PARAM_REQ_MISSING => '请求参数缺失',
        self::SERVICE_NOT_FOUND => '未发现服务',
        self::ERR_SYSTEM        => '系统异常',
        self::ERR_UPLOAD_PATH        => '上传文件路径错误',
        self::ERR_HTTP_METHOD        => '请求的HTTP METHOD不支持',
        self::SERVER_RESOURCE_UNAVAILABLE =>  '服务端资源不可用',
        self::REMOTE_SERVICE_ERROR =>  '远程服务出错',
        self::APPKEY_HIGHER_AUTHORIZATION =>  '该资源需要appkey拥有更高级的授权',
        self::MISSING_SOURCE_PARAMETER =>  '缺少source参数(appkey)',
        self::UNSUPPORTED_MEDIA_TYPE =>  '不支持的 MediaType (%s)',
        self::SYSTEM_BUSY =>  '任务过多，系统繁忙',
        self::MISSION_TIMEOUTS =>  '任务超时',
        self::RPC_ERROR =>  'RPC错误',
        self::ILLEGAL_USER =>  '不合法的农户宝用户',
        self::THREE_PARTY_INTERFACE_LIMITATIONS =>  '第三方应用访问api接口权限受限制',
        self::REQUEST_LENGTH_EXCEEDS_LIMIT =>  'HTTP请求长度超过限制',
        self::INTERFACE_NOT_EXIST =>  '接口不存在',
        self::IP_REQUEST_EXCEEDS_UPPER_LIMIT =>  'IP请求超过上限',
        self::USER_REQUEST_EXCEEDS_UPPER_LIMIT =>  '用户请求超过上限',
        self::USER_REQUEST_INTERFACE_EXCEEDED_UPPER_LIMIT =>  '用户请求接口%s超过上限',
        self::INTERFACE_IS_INVALID =>  '该接口已经废弃',
        self::PARAM_ERROR            => '错误:参数错误，请参考API文档',
        self::MANDATORY_PARAMETER_MISSING => '错误:缺失必选参数:%s，请参考API文档',
        self::PARAM_VALIDATE_ERROR     => '参数验证错误',
        self::UPLOAD_FASTDFS_ERROR     => '上传文件失败'
    ];

    /**
     * 返回错误代码的描述信息
     *
     * @param int    $code        错误代码
     * @param string $otherErrMsg 其他错误时的错误描述
     * @return string 错误代码的描述信息
     */
    public static function msg($code, $otherErrMsg = '')
    {
        if (isset(self::$msg[$code])) {
            return self::$msg[$code];
        }

        return $otherErrMsg;
    }



}